/*
 * Copyright (C) 2011  John Lawrence thegordo.john at gmail.com
 * Licensed under GPLv3 or later. see http://www.gnu.org/copyleft/gpl.html
 */

package org.jklawrencefam.server.smtp.command;

import org.jklawrencefam.annotation.smtp.SmtpCommandMarker;
import org.jklawrencefam.authentication.User;
import org.jklawrencefam.server.smtp.SmtpCode;
import org.jklawrencefam.server.smtp.state.StateParameters;

/**
 * User: John Lawrence
 * Date: 5/29/11
 * Time: 7:40 AM
 */
@SmtpCommandMarker(value = Auth.NAME, enhanced = true, keyword = "AUTH GSSAPI")
// TODO: Need to add the authentication types
public class Auth extends SmtpCommand {
    public static final String NAME = "AUTH";

    protected Auth(String CommandString) {
        super(CommandString);
    }

    @Override
    public String getReplyMessage() {
        return composeMessage(SmtpCode.OK);
    }

    @Override
    protected boolean isValid() {
        return argumentString != null;
    }

    @Override
    public void doProcessInternal() {
        User user = new User();
        String userName = state.getParameter(StateParameters.UserName, String.class);
        user.setUserName(userName);
        user.setPassword(argumentString);
        state.setParameter(StateParameters.User, user);
    }
}
